/*
 * 		CF Query Table - 1.0
 * 		Creating Dynamic tables from a Struct with Array or JSon Coldfusion Query.
 * 		Created by Roberto Fonseca Alves - www.rhfactor.com.br
 * 
 * 		Copyright 2010 www.rhfactor.com.br 
 * 		Licensed under the Apache License, Version 2.0 (the "License"); 
 * 		you may not use this file except in compliance with the License. 
 * 		You may obtain a copy of the License at 
 * 			http://www.apache.org/licenses/LICENSE-2.0 
 * 		Unless required by applicable law or agreed to in writing, software
 * 		distributed under the License is distributed on an "AS IS" BASIS,
 * 		WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * 		See the License for the specific language governing permissions and 
 * 		limitations under the License.
 */ 


 

(function($){
	$.fn.cfquerytable = function(){
		var element = this;
		var args = arguments[0] || {};
	    var query = args.query; //Required
	    
	    //Optional Arguments
	    
	    
			cfquerytable();
			function cfquerytable(){
				str = '<table class="target" cellpadding="0" cellspacing="0"><thead>'
				for(i in query['COLUMNS']){
					str+= '<th> '+ query['COLUMNS'][i] +' </th> ';
				}
				str+='</thead><tbody>';
				for(i in query.DATA){
					str+='<tr>';
						for(x=0;x<=query.DATA[i].length-1;x++){
							str+='<td>'+ query.DATA[i][x] +'</td>';
						}
					str+='</tr>';
				}
				str+='</tbody></table>';
				$(element).html(str);
				$(element).children('tbody tr:even').addClass('even');
				$(element).children('tbody tr:odd').addClass('odd');
			};
	};
})(jQuery);